package com.onlineMIS.ORM.entity.headQ.finance;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.tools.ant.types.resources.selectors.Type;

import com.onlineMIS.ORM.entity.headQ.supplier.finance.FinanceBillSupplier;
import com.onlineMIS.common.Common_util;

public class FinanceBillFlowDetailsVO extends FinanceBill implements java.util.Comparator<FinanceBillFlowDetailsVO>,Comparable<FinanceBillFlowDetailsVO>{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3316480817173942156L;
	private int flowId;
	private String financeCategoryName;
	private String flowType;//流水类型
	private int flowBelong;//流水归属（为了账目流水单据 根据单据类型，查询单据详情）
	private String flowName;
	private double total;
	private double balance;
	private double borrowerAmount;//借方金额
	private double lenderAmount;//贷方金额
	
	private String transferType;
	private String billDateS;
	private String createTimeS;
	private String comment;
	private int type;

	public  FinanceBillFlowDetailsVO() {
	
	}
	
	public FinanceBillFlowDetailsVO(double borrowerAmount,double lenderAmount) {
		this.flowName = "本日合计";
		this.borrowerAmount =borrowerAmount;
		this.lenderAmount = lenderAmount;
	}
	
	
	/**
	 * 客户/供应商 账目
	 * @param flowId
	 * @param flowName
	 * @param flowType
	 * @param total
	 * @param balance
	 * @param transferType
	 * @param billDate
	 * @param comment
	 * @param type
	 * @param financeCategory
	 */
	public FinanceBillFlowDetailsVO(int flowId,String flowName,String flowType,double total,double balance, int transferType,Date billDate,String comment,int type,FinanceCategory  financeCategory) {
		this.flowId = flowId;
		this.financeCategoryName = financeCategory.getItemName();
		this.flowName = flowName;
		this.flowType = flowType;
		this.total = total;
		this.balance = balance;
		if (FinanceCategory.ACCOUNT_TYPE_NAME_CUST.equals(flowType)) {
			FinanceBill cuBill = new FinanceBill();
			this.transferType = cuBill.getTypeHQMap().get(transferType);	
			this.flowBelong = FinanceCategory.CATEGORY_TYPE_CUST;
		}else if (FinanceCategory.ACCOUNT_TYPE_NAME_SUPPLIER.equals(flowType)) {
			FinanceBillSupplier supplier = new FinanceBillSupplier();
			this.transferType = supplier.getTypeHQMap().get(transferType);	
			this.flowBelong = FinanceCategory.CATEGORY_TYPE_SUPPLIER;
		}		
		this.billDateS = Common_util.dateFormat.format(billDate);
		this.comment = comment;
		this.type = type;
	}
	
	
	/**
	 * 总部账目
	 * @param expenseHq
	 */
	public FinanceBillFlowDetailsVO(ExpenseHq expenseHq) {
		this.flowId = expenseHq.getId();

		this.financeCategoryName = expenseHq.getFinanceCategory().getItemName();
		if (expenseHq.getType() == expenseHq.DOCUMENT_TYPE_HQ_COST) {

			this.flowName = "费用单";
			this.type = FinanceBill.FINANCE_PAID_HQ;
			this.transferType = "费用单";
		}else if (expenseHq.getType() == expenseHq.DOCUMENT_TYPE_HQ_INCOME) {
			this.flowName = "收益单";			
			this.type = FinanceBill.FINANCE_INCOME_HQ;
			this.transferType = "收益单";
		}	
		this.flowType = FinanceCategory.ACCOUNT_TYPE_NAME_HQ;
		this.total = expenseHq.getAmount();
		this.balance = 0;
		//this.transferType = FinanceCategory.ACCOUNT_TYPE_NAME_HQ;
		this.billDateS = Common_util.dateFormat.format(expenseHq.getExpenseDate());
		this.comment = expenseHq.getComment();
		this.flowBelong = FinanceCategory.CATEGORY_TYPE_HQ;
	}
	

	public FinanceBillFlowDetailsVO(ExpenseHqItem expenseHqItem) {
		ExpenseHq expenseHq = expenseHqItem.getExpenseHq();
		this.flowId = expenseHq.getId();

		this.financeCategoryName = expenseHq.getFinanceCategory().getItemName();
		if (expenseHq.getType() == expenseHq.DOCUMENT_TYPE_HQ_COST) {

			this.flowName = expenseHqItem.getExpenseHqType().getName();
			this.type = FinanceBill.FINANCE_PAID_HQ;
			this.transferType = "费用单";
		}else if (expenseHq.getType() == expenseHq.DOCUMENT_TYPE_HQ_INCOME) {
			this.flowName = expenseHqItem.getExpenseHqType().getName();			
			this.type = FinanceBill.FINANCE_INCOME_HQ;
			this.transferType = "收益单";
		}	
		this.flowType = FinanceCategory.ACCOUNT_TYPE_NAME_HQ;
		this.total = expenseHqItem.getAmount();
		this.balance = 0;
		//this.transferType = FinanceCategory.ACCOUNT_TYPE_NAME_HQ;
		this.billDateS = Common_util.dateFormat.format(expenseHq.getExpenseDate());
		this.comment = expenseHq.getComment();
		this.flowBelong = FinanceCategory.CATEGORY_TYPE_HQ;
	}



	/**
	 * 机构账目
	 * @param financeBillCorpFlow
	 * @param financeCategoryId
	 * @param isOut
	 */
	public FinanceBillFlowDetailsVO(FinanceBillCorpFlow financeBillCorpFlow,int financeCategoryId,boolean isOut) {
		this.flowId = financeBillCorpFlow.getId();
		
		if (isOut && financeCategoryId == financeBillCorpFlow.getFromAcctId().getId()) {
			this.financeCategoryName = financeBillCorpFlow.getFromAcctId().getItemName();
			this.transferType = "机构转出";
			//this.flowName = "【" +financeBillCorpFlow.getFromAcctId().getItemName()+"】 --转出--【"+financeBillCorpFlow.getToAcctId().getItemName()+"】";
			this.flowName = financeBillCorpFlow.getToAcctId().getItemName();
			this.type = FinanceBill.FINANCE_PAID_HQ;
		}
		if (!isOut && financeCategoryId == financeBillCorpFlow.getToAcctId().getId()) {
			this.financeCategoryName = financeBillCorpFlow.getToAcctId().getItemName();
			this.transferType = "机构转入";
			//this.flowName = "【" +financeBillCorpFlow.getFromAcctId().getItemName()+"】 --转入--【"+financeBillCorpFlow.getToAcctId().getItemName()+"】";
			this.flowName = financeBillCorpFlow.getFromAcctId().getItemName();
			this.type = FinanceBill.FINANCE_INCOME_HQ;
		}			
		
		this.flowType = "机构账目";
		this.total = financeBillCorpFlow.getAmount();
		this.balance = 0;		
		this.billDateS = Common_util.dateFormat.format(financeBillCorpFlow.getDate());
		this.comment = financeBillCorpFlow.getComment();
		this.flowBelong = FinanceCategory.CATEGORY_TYPE_INSTITUTION;
	}
	
	public FinanceBillFlowDetailsVO(FinanceBillCorpFlow financeBillCorpFlow,int financeCategoryId) {
		this.flowId = financeBillCorpFlow.getId();
		
		if (financeCategoryId == financeBillCorpFlow.getFromAcctId().getId()) {
			this.financeCategoryName = financeBillCorpFlow.getFromAcctId().getItemName();
			this.transferType = "机构转出";
			//this.flowName = "【" +financeBillCorpFlow.getFromAcctId().getItemName()+"】 --转出--【"+financeBillCorpFlow.getToAcctId().getItemName()+"】";
			this.flowName = financeBillCorpFlow.getToAcctId().getItemName();
			this.type = FinanceBill.FINANCE_PAID_HQ;
		}
		if (financeCategoryId == financeBillCorpFlow.getToAcctId().getId()) {
			this.financeCategoryName = financeBillCorpFlow.getToAcctId().getItemName();
			this.transferType = "机构转入";
			//this.flowName = "【" +financeBillCorpFlow.getFromAcctId().getItemName()+"】 --转入--【"+financeBillCorpFlow.getToAcctId().getItemName()+"】";
			this.flowName = financeBillCorpFlow.getFromAcctId().getItemName();
			this.type = FinanceBill.FINANCE_INCOME_HQ;
		}			
		
		this.flowType = "机构账目";
		this.total = financeBillCorpFlow.getAmount();
		this.balance = 0;		
		this.billDateS = Common_util.dateFormat.format(financeBillCorpFlow.getDate());
		this.comment = financeBillCorpFlow.getComment();
		this.flowBelong = FinanceCategory.CATEGORY_TYPE_INSTITUTION;
	}


	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public double getBalance() {
		return balance;
	}

	public void setBalance(double balance) {
		this.balance = balance;
	}

	public String getTransferType() {
		return transferType;
	}
	public void setTransferType(String transferType) {
		this.transferType = transferType;
	}
	public String getBillDateS() {
		return billDateS;
	}
	public void setBillDateS(Date billDate) {
		if(billDate != null) {
			this.billDateS = Common_util.dateFormat.format(billDate);
		}	
	}
	public String getComment() {
		return comment;
	}
	public void setComment(String comment) {
		this.comment = comment;
	}
	public int getFlowId() {
		return flowId;
	}
	public void setFlowId(int flowId) {
		this.flowId = flowId;
	}
	public String getFlowType() {
		return flowType;
	}
	public void setFlowType(String flowType) {
		this.flowType = flowType;
	}
	public String getFlowName() {
		return flowName;
	}
	public void setFlowName(String flowName) {
		this.flowName = flowName;
	}
	public double getTotal() {
		return total;
	}
	public void setTotal(double total) {
		this.total = total;
	}


	public double getBorrowerAmount() {
		return borrowerAmount;
	}

	public void setBorrowerAmount(double borrowerAmount) {
		this.borrowerAmount = borrowerAmount;
	}

	public double getLenderAmount() {
		return lenderAmount;
	}

	public void setLenderAmount(double lenderAmount) {
		this.lenderAmount = lenderAmount;
	}

	public String getCreateTimeS() {
		return createTimeS;
	}

	public void setCreateTimeS(String createTimeS) {
		this.createTimeS = createTimeS;
	}
	

	public int getFlowBelong() {
		return flowBelong;
	}

	public void setFlowBelong(int flowBelong) {
		this.flowBelong = flowBelong;
	}
	

	public String getFinanceCategoryName() {
		return financeCategoryName;
	}

	public void setFinanceCategoryName(String financeCategoryName) {
		this.financeCategoryName = financeCategoryName;
	}

	@Override
	public int compare(FinanceBillFlowDetailsVO o1, FinanceBillFlowDetailsVO o2) {
			 String date1 = o1.getBillDateS();
			 String date2 = o2.getBillDateS();
			 return date1.compareTo(date2); 
	}

	@Override
	public int compareTo(FinanceBillFlowDetailsVO o) {
		int flag = o.getBillDate().compareTo(this.getBillDate());
		return flag;
	}
	

}
